$(function () {
    obj.init();

});

function showProgress(target) {
    var sblId = $(target).attr('nodeId');
    window.top.xhTop.showModal({
        title: '书本库',
        content: '<iframe  src="'+baseUrl+'school_book/booksTab/'+sblId+'"  style="width: 100%;;border-style: none;padding: 0px;height:600px"  scrolling="yes"   ></iframe>',
        backClose: false,
        width:950
    });
}

var obj = new function () {
    'use strict';
    return {
        dataGrid:null,
        titleRow:null,
        tabRow:null,
        init:function () {

            this.titleRow = $('#titleRow');
            this.tabRow   = $('#tabRow');
            this.dataGrid = new xhDataGrid($('#list'), 'school_book/getList');
            this.dataGrid.parseToolbar().init().activeButton(['bt_list_del'], ['bt_list_edit','bt_list_contact', 'bt_list_update_class', 'bt_list_syn_group', 'bt_list_weekly']);
            this.funObj().bindDataGridEvent();
            this.listener();
        },
        listener:function () {
            var $this = this;

            //新增事件按钮
            $('#bt_list_add').on('click',function () {
                $this.funObj().openAddForm();
            });

            $('#bt_list_del').on('click',function () {
               $this.funObj().askDelQuestion();
            });

            $('#tabReturn').on('click',function () {
                $this.funObj().goToList();
            });

            $('#bt_list_search').click(function () {
                $this.funObj().search();
            });
            // console.log($('.progress'));
            // $('#list').on('click','.progress',function () {
            //
            //     $this.funObj().openProgress(sblId);
            // });

        },
        funObj:function () {
            var $this = this;
            return {
                bindDataGridEvent:function () {

                    // $this.dataGrid.onDblClickCell = function(rowIndex, field, value){
                    //     var rowData = $this.dataGrid.command('getRows')[rowIndex];
                    //     switch (field){
                    //         case 'sSchoolName': break;
                    //         case 'progress' : $this.funObj().openProgress(rowData);break;
                    //     }
                    // };
                    $this.dataGrid.onDblClickRow = function (rowIndex,rowData) {
                        $this.funObj().openSchoolBook(rowData);
                    }
                },
                openAddForm:function () {
                    window.top.xhTop.showModal({
                        title: '选择学校',
                        content: '<iframe  src="'+baseUrl+'school_book/addForm"  style="width: 100%;;border-style: none;padding: 0px;height:200px"  scrolling="yes"   ></iframe>',
                        button:'提交'
                    });
                },
                goToList:function () {
                    $this.titleRow.hide();
                    $this.tabRow.hide();
                    $this.dataGrid.reload();
                    xhExtra.backToList();

                },
                askDelQuestion:function () {
                    var iSBLId = $this.dataGrid.getSelectValue('iSBLId');
                    xhExtra.askChangeStatus('school_book/delInfo',{iSBLId:iSBLId},null,null,function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        $this.dataGrid.reload();
                    });
                },
                openSchoolBook:function (rowData) {
                    $('#title_school').contents()[0]['data'] = rowData['sSchoolName'];
                    window.frames['tabFrame'].location.href = baseUrl+'school_book/schTab/'+rowData['iSBLId'];
                    $this.titleRow.show();
                    $this.tabRow.show();
                    xhExtra.forwardToForm(true);
                },
                search:function () {
                    var key = xhExtra.getValue($('#list_search_vague'));
                    $this.dataGrid.reload({key:key});
                }
                // openProgress:function (sblId) {
                //     window.top.xhTop.showModal({
                //         title: '书本库',
                //         content: '<iframe  src="'+baseUrl+'school_book/booksTab/'+sblId+'"  style="width: 100%;;border-style: none;padding: 0px;height:400px"  scrolling="yes"   ></iframe>',
                //         backClose: false,
                //         width:950
                //     });
                // }
            }
        }
    }
};